<template>
  <div class="playlists-container">
    <!-- 同步 -->
    <div
      class="top-card"
      v-if="listName"
    >
      <div class="icon-wrap">
        <img
          :src="listCover"
          alt=""
        />
      </div>
      <div class="content-wrap">
        <div class="tag">精品歌单</div>
        <div class="title">
          {{ listName }}
        </div>
        <div class="info">{{ listDesc }}</div>
      </div>
      <img
        :src="listCover"
        alt=""
        class="bg"
      />
      <div class="bg-mask"></div>
    </div>
    <div class="tab-container">
      <!-- tab栏 顶部 -->
      <div class="tab-bar">
        <span
          class="item"
          :class="{ active: cat == '全部' }"
          @click="cat = '全部'"
        >全部</span>
        <span
          class="item"
          :class="{ active: cat == '欧美' }"
          @click="cat = '欧美'"
        >欧美</span>
        <span
          class="item"
          :class="{ active: cat == '华语' }"
          @click="cat = '华语'"
        >华语</span>
        <span
          class="item"
          :class="{ active: cat == '流行' }"
          @click="cat = '流行'"
        >流行</span>
        <span
          class="item"
          :class="{ active: cat == '说唱' }"
          @click="cat = '说唱'"
        >说唱</span>
        <span
          class="item"
          :class="{ active: cat == '摇滚' }"
          @click="cat = '摇滚'"
        >摇滚</span>
        <span
          class="item"
          :class="{ active: cat == '民谣' }"
          @click="cat = '民谣'"
        >民谣</span>
        <span
          class="item"
          :class="{ active: cat == '电子' }"
          @click="cat = '电子'"
        >电子</span>
        <span
          class="item"
          :class="{ active: cat == '轻音乐' }"
          @click="cat = '轻音乐'"
        >轻音乐</span>
        <span
          class="item"
          :class="{ active: cat == '影视原声' }"
          @click="cat = '影视原声'"
        >影视原声</span>
        <span
          class="item"
          :class="{ active: cat == 'ACG' }"
          @click="cat = 'ACG'"
        >ACG</span>
        <span
          class="item"
          :class="{ active: cat == '怀旧' }"
          @click="cat = '怀旧'"
        >怀旧</span>
        <span
          class="item"
          :class="{ active: cat == '治愈' }"
          @click="cat = '治愈'"
        >治愈</span>
        <span
          class="item"
          :class="{ active: cat == '旅行' }"
          @click="cat = '旅行'"
        >旅行</span>
      </div>
      <!-- tab的内容区域 -->
      <div class="tab-content">
        <div class="items">
          <div
            class="item"
            v-for="(item,index) in playList"
            :key="index"
            @click="toPlayList(item.id)"
          >
            <div class="img-wrap">
              <div class="num-wrap">
                播放量:
                <span class="num">{{ item.playCount | formatCount }}</span>
              </div>
              <img
                :src="item.coverImgUrl"
                alt=""
              />
              <span class=""></span>
            </div>
            <p class="name">{{ item.description }}</p>
          </div>
        </div>
      </div>
    </div>
    <!-- 分页器 -->
    <el-pagination
      @current-change="handleCurrentChange"
      background
      layout="prev, pager, next"
      :total="total"
      :page-size="10"
      :current-page="page"
    >
    </el-pagination>
  </div>
</template>

<script>
import axios from "axios";
export default {
  name: "recommend",
  data() {
    return {
      // 歌单分类
      cat: "全部",
      // 顶部的标题
      listName: "",
      // 顶部的描述
      listDesc: "",
      // 顶部的封面
      listCover: "",
      // 总条数
      total: 0,
      // 页码
      page: 1,
      // 歌单列表
      playList: []
    };
  },
  watch: {
    cat() {
      this.getData();
    }
  },
  created() {
    this.getData();
  },
  methods: {
    // 去歌单详情页面
    toPlayList(id) {
      this.$router.push(`/playList?id=${id}`);
    },
    // 获取歌单信息
    getData() {
      axios({
        url: "https://autumnfish.cn/top/playlist/highquality",
        method: "get",
        params: {
          limit: 1,
          cat: this.cat
        }
      }).then(res => {
          console.log(res)
        if (res.data.playlists.length != 0) {
          this.listName = res.data.playlists[0].name;
          this.listDesc = res.data.playlists[0].description;
          this.listCover = res.data.playlists[0].coverImgUrl;
        } else {
          this.listName = "";
        }
      });
      // 底部的歌单信息
      axios({
        url: "https://autumnfish.cn/top/playlist/highquality",
        method: "get",
        params: {
          cat: this.cat,
          offset: (this.page - 1) * 10
        }
      }).then(res => {
        // window.console.log(res);
        this.playList = res.data.playlists;
        this.total = res.data.total;
      });
    },
    handleCurrentChange(val) {
      this.page = val;
      this.getData();
    }
  }
};
</script>

<style lang="scss">
.playlists-container {
  .top-card {
    padding: 20px;
    height: 200px;
    display: flex;
    position: relative;
    overflow: hidden;
    border-radius: 5px;
    .icon-wrap {
      margin-right: 20px;
      z-index: 1;
      img {
        width: 160px;
        height: 160px;
      }
    }
    .content-wrap {
      z-index: 1;
      .tag {
        color: #dfac67;
        border: 1px solid #dfac67;
        width: 100px;
        height: 30px;
        text-align: center;
        border-radius: 5px;
        font-size: 16px;
        line-height: 30px;
        cursor: pointer;
      }
      .title {
        color: white;
        padding-top: 10px;
      }
      .info {
        color: #888482;
        font-size: 14px;
        padding-top: 5px;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 5;
      }
    }
    .bg {
      width: 100%;
      position: absolute;
      left: 0;
      top: 0;
      right: 0;
      bottom: 0;
      z-index: 0;
      filter: blur(20px);
    }
    .bg-mask {
      width: 100%;
      position: absolute;
      left: 0;
      top: 0;
      right: 0;
      bottom: 0;
      background-color: rgba(0, 0, 0, 0.5);
    }
  }
  .tab-container {
    padding-top: 30px;
    .tab-bar {
      display: flex;
      justify-content: flex-end;
      .item {
        font-size: 15px;
        color: gray;
        margin-right: 20px;
        cursor: pointer;
        &.active {
          color: #dd6d60;
        }
      }
    }
    .tab-content {
      margin-top: 20px;
      .items {
        display: flex;
        flex-wrap: wrap;
        .item {
          width: 200px;
          margin: 10px;
          position: relative;
          overflow: hidden;
          cursor: pointer;
          img {
            width: 200px;
            height: 200px;
            border-radius: 5px;
          }
          .num-wrap {
            position: absolute;
            top: 0;
            left: 0;
            font-size: 14px;
            color: white;
            line-height: 30px;
            background: rgba(0, 0, 0, 0.5);
            height: 30px;
            width: 100%;
            padding-left: 5px;
            top: -30px;
            overflow: hidden;
          }
          &:hover .num-wrap {
            top: 0;
          }
          .img-wrap {
            position: relative;
            .icon-play {
              position: absolute;
              right: 10px;
              bottom: 13px;
              width: 40px;
              height: 40px;
              color: #dd6d60;
              font-size: 20px;
              border-radius: 50%;
              display: flex;
              align-items: center;
              justify-content: center;
              background: rgba(255, 255, 255, 0.8);
              opacity: 0;
              &::before {
                transform: translateX(3px);
              }
            }
            &:hover .icon-play {
              opacity: 1;
            }
          }
          .name {
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 2;
            font-size: 14px;
          }
        }
      }
    }
    
  }
   .el-pagination {
      margin-top: 50px;
      text-align: center;
    }
    .el-pagination.is-background .el-pager li:not(.disabled).active {
      background-color: #dd6d60;
    }
}
</style>
